package com.bcx.crm.plat.core.servlet;


import com.bcx.crm.plat.core.manage.TXManage;
import com.bcx.crm.plat.core.utils.ServletUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**新增异常通知
 * Created by ys on 2017/12/12.
 */
public class DispatcherServlet extends org.springframework.web.servlet.DispatcherServlet {
    /**
     * 当找不到URI的控制器时的处理方式
     * @param request 请求
     * @param response 返回
     * @throws Exception 可能抛出的异常
     */
    @Override
    protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response) throws Exception {
        super.noHandlerFound(request, response);
    }

    /**
     * 执行dispatch 开启事物管理
     * @param request 请求
     * @param response 返回
     * @throws Exception
     */
    @Override
    protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //需要平台处理时开启事物
        if (ServletUtils.uriNeedHandle(request.getRequestURI())){
            TXManage.doInRequiredTX((manager,status)->{
                super.doDispatch(request, response);
            });
        }else {
            super.doDispatch(request, response);
        }
    }
}
